<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        input {
            border: 1px solid red
        }

        .content {
            width: 100px;
            height: 100px;
            background: burlywood;
            ;
            ;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 日历 弹层 -->
        <div v-click-outside>
            <input type="text">
            <div class="content" v-if="isShow">content
                <button>点我 </button>
            </div>
        </div>

    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        // 可以实现 点击时判断是否存在当前的dom中
        let vm = new Vue({
            el: '#app',
            directives: { // 可以声明多个所以是复数形式
                clickOutside: {
                    bind(el, bindings, vnode) {
                        el.fn = (e) => {
                            if (el.contains(e.target)) {
                                console.log('111111111111111');
                                vnode.context['focus']()
                            } else {
                                vnode.context['blur']()
                            }
                        }
                        document.addEventListener('click', el.fn)
                    },
                    unbind(el) { // 事件绑定必须要解绑
                        document.removeEventListener('click', el.fn)
                    }
                }
            },
            data: {
                isShow: false
            },
            methods: {
                blur() {
                    this.isShow = false;
                },
                focus() {
                    this.isShow = true;
                }
            }
        });
    </script>
</body>

</html>